def pr (num):
    fl = True
    for i in range(2, num):
        if num % i == 0:
            fl = False
            break
    return fl
    
a, b, c, = input().split()
m = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
if a in m and b in m and c in m and a!='zero':
    num = m.index(a) * 100 + m.index(b) * 10 + m.index(c)
    print(num)
    if pr(num)==True:
        print(num)
    else:
        x = y = 0
        for r in range(num+1, 1100):
            if pr(r) == True:
                x = r
                break
        for j in range(num-1, 0, -1):
            if pr(j)==True:
                y = j
                break
    if x - num > num - y:
        print(y)
    elif x - num <  num - y:
        print(x)
    elif x - num < num - y:
        print(y)
else:
    
    print('Wrong input')
